home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 733 < prev    next >
Text File  |  1996-08-06  |  2KB  |  69 lines

  1. Path: rover.ucs.ualberta.ca!mcbride
  2. From: mcbride@ee.ualberta.ca (Darin McBride)
  3. Newsgroups: comp.lang.c,comp.std.c,finet.atk.kielet.c
  4. Subject: Re: TYPEDEF and Watcom C++ 10.5
  5. Followup-To: comp.lang.c,comp.std.c,finet.atk.kielet.c
  6. Date: 12 Apr 1996 19:20:43 GMT
  7. Organization: University of Alberta Electrical Engineering Department
  8. Distribution: world
  9. Message-ID: <4kmaeb$10qi@pulp.ucs.ualberta.ca>
  10. References: <4jlu1r$cs7@nic.dataphone.se>
  11. NNTP-Posting-Host: nyquist.ee.ualberta.ca
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. Jarmo Paavilainen (skorpio@dataphone.se) wrote:
  15.  
  16. > typedef struct
  17. > {
  18. > WORD    CheckSum;
  19. > WORD    Version;
  20. > BYTE    PatchLevel;
  21. > BYTE    Name[21];
  22. > WORD    MarkerVersion;
  23. > }VERSION_TAG_STRUCT;
  24.  
  25. > Shouldn't sizeof(VERSION_TAG_STRUCT) always result in 28. By other words
  26. > shouldn't WORD always be 16 bits and BYTE 8 bits.
  27.  
  28. Usually, yes.
  29.  
  30. > If so why does my compiler claim that sizeof(VERSION_TAG_STRUCT) == 34.
  31. > All this in 32 bit OS/2 PM and Watcom C++ 10.5
  32.  
  33. You probably have double-word alignment (i.e., pack(4)):
  34.  
  35. [ Checksum ] [ Checksum ] [ pad ] [ pad ]
  36. [ Version  ] [ Version  ] [ pad ] [ pad ]
  37. [ Patchlvl ] [ pad      ] [ pad ] [ pad ]
  38. [ Name ...... /* few lines of this until... */
  39. [ Name     ] [ pad      ] [ pad ] [ pad ]
  40. [ MarkerV  ] [ MarkerV  ]
  41.  
  42. Perhaps it doesn't put the padding after PatchLevel, and that would be
  43. 34 bytes.
  44.  
  45. If you require it to be 28 bytes, do the following:
  46.  
  47. #if __WATCOMC__ > 1000
  48. #pragma pack(push,1);
  49. #else
  50. #pragma pack(1);
  51. #endif
  52.  
  53. /* define struct here */
  54.  
  55. #if __WATCOMC__ > 1000
  56. #pragma pack(pop);
  57. #else
  58. #pragma pack();
  59. #endif
  60.  
  61. --
  62. Darin McBride:mcbride@ee.ualberta.ca/mcbride@tower.bohica.net
  63.  
  64. Enjoy each day as if it were your last, care about each moment as if
  65. it were your last for one day, one moment, you *will* be right!
  66.  
  67. Tips & Tricks for IBM Hardware, MSDOS, OS2, Windows (including Win'95):
  68.     http://www.ee.ualberta.ca/~mcbride/tiptrick.html
  69.